const router = require('koa-router')() // 一边导入一边实例化
// 操作数据库的接口
const { getToken, Queryurl } = require('../../config/databaseapi.js')
// 注册接口
router.post('/queryannouncement', async (ctx) => {
    console.log('调用查询公告方法')
    // const { queryParams } = ctx.request.body;
    console.log('查询参数',ctx.request.body);
    const queryParams = {};
    for(let key in ctx.request.body){
        if(key!=="pageNo" && ctx.request.body[key]!==""){
            queryParams[key] = ctx.request.body[key];
        }
    }
    console.log(queryParams)
    const res = await new getToken().posteve(Queryurl,`db.collection("announcement").where(${JSON.stringify(queryParams)}).skip(${(ctx.request.body.pageNo-1)*10}).get()`);
    console.log(res);
    ctx.body = res;
})

module.exports = router.routes()